import { Node, math, Label } from "cc";
import View from "./View";
import { Layer } from "../FragmentManager";
import { UITransform } from "cc";

export default class Toast extends View {

    layer(): Layer {
        return Layer.Notify;
    }

    create(root: Node) {
        const uiTransform = root.getComponent(UITransform);
        if (!uiTransform) {
            throw 'root Node need has UITransform Component';
        }
        const toast = new Node();
        const transform = toast.addComponent(UITransform);
        transform.width = uiTransform.width * 0.8;
        const label = toast.addComponent(Label);
        label.color = math.Color.RED;
        label.fontSize = 20;
        label.lineHeight = 20;
        label.overflow = Label.Overflow.SHRINK;
        return toast;
    }

}